package com.medical.project.system.controller;

import java.util.List;

import com.medical.common.utils.IdUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.medical.framework.aspectj.lang.annotation.Log;
import com.medical.framework.aspectj.lang.enums.BusinessType;
import com.medical.project.system.domain.Institution;
import com.medical.project.system.service.IInstitutionService;
import com.medical.framework.web.controller.BaseController;
import com.medical.framework.web.domain.AjaxResult;
import com.medical.common.utils.poi.ExcelUtil;
import com.medical.framework.web.page.TableDataInfo;

/**
 * 农合经办点Controller
 *
 * @author tale
 * @date 2020-06-20
 */
@RestController
@RequestMapping("/system/institution")
public class InstitutionController extends BaseController {
    @Autowired
    private IInstitutionService institutionService;

    /**
     * 查询农合经办点列表
     */
    @PreAuthorize("@ss.hasPermi('system:institution:list')")
    @GetMapping("/list")
    public TableDataInfo list(Institution institution) {
        startPage();
        List<Institution> list = institutionService.selectInstitutionList(institution);
        return getDataTable(list);
    }

    /**
     * 导出农合经办点列表
     */
    @PreAuthorize("@ss.hasPermi('system:institution:export')")
    @Log(title = "农合经办点", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Institution institution) {
        List<Institution> list = institutionService.selectInstitutionList(institution);
        ExcelUtil<Institution> util = new ExcelUtil<Institution>(Institution.class);
        return util.exportExcel(list, "institution");
    }

    /**
     * 获取农合经办点详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:institution:query')")
    @GetMapping(value = "/{institutionCode}")
    public AjaxResult getInfo(@PathVariable("institutionCode") String institutionCode) {
        return AjaxResult.success(institutionService.selectInstitutionById(institutionCode));
    }

    /**
     * 新增农合经办点
     */
    @PreAuthorize("@ss.hasPermi('system:institution:add')")
    @Log(title = "农合经办点", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Institution institution) {
        institution.setInstitutionCode(IdUtils.simpleUUID());
        return toAjax(institutionService.insertInstitution(institution));
    }

    /**
     * 修改农合经办点
     */
    @PreAuthorize("@ss.hasPermi('system:institution:edit')")
    @Log(title = "农合经办点", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Institution institution) {
        return toAjax(institutionService.updateInstitution(institution));
    }

    /**
     * 删除农合经办点
     */
    @PreAuthorize("@ss.hasPermi('system:institution:remove')")
    @Log(title = "农合经办点", businessType = BusinessType.DELETE)
    @DeleteMapping("/{institutionCodes}")
    public AjaxResult remove(@PathVariable String[] institutionCodes) {
        return toAjax(institutionService.deleteInstitutionByIds(institutionCodes));
    }
}
